{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "59015f02",
   "metadata": {},
   "source": [
    "-----------\n",
    "* 日期：2022-10-12 \\week 08(周三）\n",
    "* 课程：python\n",
    "* 记录人：洪梦瑶\n",
    "-----------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5da72724",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "\n",
    "> 1. 有序的数据结构-字符串\n",
    ">> 1. 字符串的基本概念（回顾）\n",
    ">>> 1. Single quotes: 'allows embedded \"double\" quotes'\n",
    ">>> 2. Double quotes: \"allows embedded 'single' quotes\"\n",
    ">>> 3. Triple quoted: '''Three single quotes''', \"\"\"Three double quotes\"\"\"\n",
    ">> 2. 字符串的性质和方法\n",
    "> 2. 有序的数据结构-列表"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "70d35ae6",
   "metadata": {},
   "source": [
    "## 1.字符串的性质和方法\n",
    "* 字符串的性质\n",
    "> 1. 字符串的有序性\n",
    "> 2. 字符串是有长度的\n",
    ">> 1. 使用len（）检查字符串的长度\n",
    "* 字符串的基本方法\n",
    "> 1. 字符串的取值：str[index]\n",
    "> 2. 字符串的切片：str[start,stop],stop取不到\n",
    "> 3. 字符串的拼接：+\n",
    "> 4. in检查成员是否存在\n",
    "* 字符串的一般方法（function/Methods 函数/方法）\n",
    "> 1. isdigit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "id": "c3dfb96d",
   "metadata": {},
   "outputs": [],
   "source": [
    "text = \"广州南方学院校记者团\" # 广州南方学院校记者团------values\n",
    "                              # 0 1 2 3 4 5 6 7 8 9 ------index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "id": "70cebda6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 135,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "id": "afe8de9c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'团'"
      ]
     },
     "execution_count": 136,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "id": "e7965ce6",
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexError",
     "evalue": "string index out of range",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexError\u001b[0m                                Traceback (most recent call last)",
      "Input \u001b[1;32mIn [137]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mtext\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m100\u001b[39;49m\u001b[43m]\u001b[49m\n",
      "\u001b[1;31mIndexError\u001b[0m: string index out of range"
     ]
    }
   ],
   "source": [
    "text[100]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "id": "bba60886",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "10"
      ]
     },
     "execution_count": 138,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(text)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "id": "17c3f349",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南'"
      ]
     },
     "execution_count": 139,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0]+text[1]+text[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "id": "b3f91aba",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 140,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "id": "8f629399",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院校记者团'"
      ]
     },
     "execution_count": 141,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "id": "4c1b9616",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 142,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "id": "e7720541",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'校记者团'"
      ]
     },
     "execution_count": 143,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[-4:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "id": "f6211e9f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院校记者团广州南方学院校记者团广州南方学院校记者团'"
      ]
     },
     "execution_count": 144,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 * text"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bc3a8599",
   "metadata": {},
   "source": [
    "* in 检查成员对象  —— x in s\n",
    "* count()检查字符串出现的次数 —— s.count(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "id": "f67733fa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 145,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"广州\" in text"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "id": "2f5881d7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 146,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text.count(\"广州\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "id": "7afdf301",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 147,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "3 * text.count(\"广州\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7c8e1f2c",
   "metadata": {},
   "source": [
    "* isdigit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "id": "10081f74",
   "metadata": {},
   "outputs": [],
   "source": [
    "age_1 = 19\n",
    "age_2 = \"19\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "id": "05bfdc72",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "19 <class 'int'>\n",
      "19 <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(age_1,type(age_1))\n",
    "print(age_2,type(age_2)) # int（整数）和str（字符串） 不能一起运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "id": "407dee18",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "unsupported operand type(s) for +: 'int' and 'str'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [150]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mage_1\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mage_2\u001b[49m\n",
      "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'int' and 'str'"
     ]
    }
   ],
   "source": [
    "age_1 + age_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "id": "1f36dc7c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "38\n"
     ]
    }
   ],
   "source": [
    "# 如果字符串是数值，可以用int转换成真正的数值\n",
    "if age_2.isdigit():\n",
    "    print(age_1 + int(age_2))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1ed92611",
   "metadata": {},
   "source": [
    "## 2.有序的数据结构-列表(List)\n",
    "* 1.列表的概念和基本性质\n",
    "> 1. Python knows a number of compound data types, used to group together other values. The most versatile is the list, which can be written as a list of comma-separated values (items) between square brackets. Lists might contain items of different types, but usually the items all have the same type.\n",
    "* 2.列表的一般方法\n",
    "> 1. 使用.Tab键查看列表的方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3ba33573",
   "metadata": {},
   "source": [
    "### 2.1 列表的性质\n",
    "* 和字符串的运算法则完全一致\n",
    "* 注意：字符串是对字符进行操作，列表是对items（元素）进行操作的"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "id": "02c07778",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'2'"
      ]
     },
     "execution_count": 152,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text = \"378235365\"\n",
    "text[3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "id": "a866c406",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 153,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 列表的形式\n",
    "squares = [1, 4, 9, 16, 25] # 列表里面放数值\n",
    "squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "id": "e0a0da2f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 154,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares[4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "id": "f76e54df",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 155,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "4 in squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "id": "7e2d9d50",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 156,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "5 in squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "id": "2c2429e2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 157,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares.count(9)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "id": "56773d7a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 158,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Jack\",\"Alex\",\"Marry\",\"Jan\"] # 列表里面放字符串\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "id": "e8fddda8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 'Jack', 'Alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 159,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "squares + names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "id": "538e8d6a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 4, 9, 16, 25, 1, 4, 9, 16, 25]"
      ]
     },
     "execution_count": 160,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2*squares"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "id": "c5caf15e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 18, '李华', 20]"
      ]
     },
     "execution_count": 161,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info = [\"Jack\",18,\"李华\",20]\n",
    "info"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "id": "ab0eb92b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Alex', 'Marry']"
      ]
     },
     "execution_count": 162,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[1:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "id": "83fd91e9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Marry', 'Jan']"
      ]
     },
     "execution_count": 163,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[-2:]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "41112743",
   "metadata": {},
   "source": [
    "* 取出\"Jack\",\"Marry\"（用切片的方法）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "id": "24f3e71c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Marry']"
      ]
     },
     "execution_count": 164,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[:3:2] # 先取出前3个，然后在这3个中，步长（step）是2，取出目标"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ae96454",
   "metadata": {},
   "source": [
    "* 2.列表的一般方法\n",
    "> 1. 增加(append——增加object到列表末尾）\n",
    "> 2. 删除\n",
    "> 3. 改\n",
    "> 4. 查：in\n",
    "* 3.列表的学习方法（步骤）\n",
    "> 1. 使用.Tab键查看列表的方法\n",
    "> 2. 使用help（查看方法的使用规则）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 165,
   "id": "961ea64d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan']"
      ]
     },
     "execution_count": 165,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Jack\",\"Alex\",\"Marry\",\"Jan\"] \n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 168,
   "id": "c4f771e3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function append:\n",
      "\n",
      "append(object, /) method of builtins.list instance\n",
      "    Append object to the end of the list.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(names.append)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "id": "8d8b0b69",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.append(\"Lihua\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "id": "4f6a1f9a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Jack', 'Alex', 'Marry', 'Jan', 'Lihua']"
      ]
     },
     "execution_count": 170,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bfbe2fed",
   "metadata": {},
   "source": [
    "# 课后作业\n",
    "* 列表的方法（尝试所有的方法）\n",
    "* 总结列表的方法学习心得（Tables表格形式总结）[www.markdownguide.org]\n",
    "| 列表的方法           | Description | 使用方法| 备注 |\n",
    "|------------------|------------------|-------------|--------|\n",
    "| append        | Append----增加   |  str.append(\"\")|无|"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
